package com.micro.demo.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.netflix.loadbalancer.RoundRobinRule;
import com.ribbon.MyFiveRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class ConfigBean
{
    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate()
    {
         return new RestTemplate();
    }
    /**自定义配置ribbon负载均衡算法
     * @return
     */
//    @Bean
//    public IRule myRule(){
//        return new RoundRobinRule();//轮询
//        //return new RetryRule();//重试
////        return new RandomRule();//随机
////        return new MyFiveRule(); //自定义负载均衡 每个服务调用三次
//    }
}